package com.net.xpay.common.manager.impl.operator;

import com.google.common.base.Preconditions;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.common.manager.AbstractVersionedManager;
import com.net.xpay.common.dao.operator.OperatorUserMapper;
import com.net.xpay.common.domain.operator.OperatorUser;
import com.net.xpay.common.manager.operator.OperatorUserManager;
import com.net.xpay.core.model.OperatorUsersSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class OperatorUserManagerImpl extends AbstractVersionedManager<OperatorUser> implements OperatorUserManager{

    @Autowired
    private OperatorUserMapper mapper;


    @Override
    protected BasicMapper<Long, OperatorUser> getMapper() {
        return mapper;
    }

    @Override
    public OperatorUser findByMobile(String mobile) {
        Preconditions.checkArgument(mobile != null );
        OperatorUser condition = new OperatorUser();
        condition.setMobile(mobile);
        return getByCondition(condition);
    }

    @Override
    public List<OperatorUser> search(OperatorUsersSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(OperatorUsersSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }
}
